// 11-散列3 QQ帐户的申请与登陆

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../base/HashTable.c"

/* current =========================================*/
#define QQLength 12
#define PasswordLength 17

typedef struct {
    char qq[QQLength];
    char password[PasswordLength];
} QQ;

// HashTable 中用到的3个函数
int hash(void* qq) {
    return atoi(qq+3);
}

int sameKey(void* a, void* b) {
    return strcmp(a, b) == 0;
}

void destroyKeyAndValue(void* key, void* value) {
    free(value);
}

QQ *createQQ(char* qq, char* password) {
    QQ* q = (QQ*) malloc(sizeof(QQ));
    strcpy(q->qq, qq);
    strcpy(q->password, password);
    return q;
}

int main() {
    int n;
    scanf("%d", &n);
    HashTable *h = createHashTable(n*2, hash, sameKey, destroyKeyAndValue);
    for (int i=0; i<n; i++) {
        char action[2];
        char qq[QQLength];
        char password[PasswordLength];
        scanf("%s %s %s", action, qq, password);
        switch (action[0]) {
            case 'L': {
                QQ* q = find(h, qq);
                if (q == NULL) {
                    printf("ERROR: Not Exist\n");
                } else if (strcmp(q->password, password) == 0) {
                    printf("Login: OK\n");
                } else {
                    printf("ERROR: Wrong PW\n");
                }
                break;
            }
            case 'N': {
                QQ* q = find(h, qq);
                if (q != NULL) {
                    printf("ERROR: Exist\n");
                } else {
                    q = createQQ(qq, password);
                    insert(h, q->qq, q);
                    printf("New: OK\n");
                }
                break;
            }
        }
    }
    destroyHashTable(h);
    return 0;
}
